package com.hiraeth.common.utils;

import com.hiraeth.modules.monitor.model.ScrapeConfig;

import java.util.List;

/**
 * prometheus工具类
 * @author xuning
 *
 */
public class PrometheusUtils {

	/**
	 * 判断配置列表中是否已存在相同job_name的scrape_config
	 * @param scrapeConfigs scrape_config列表
	 * @param scrapeConfig 待检查的scrape_config
	 * @return
	 */
	public static boolean isAlreadyExist(List<ScrapeConfig> scrapeConfigs, ScrapeConfig scrapeConfig) {
		if (scrapeConfig == null) return true;
		return isAlreadyExist(scrapeConfigs, scrapeConfig.getJob_name());
	}
	/**
	 * 判断配置列表中是否已存在相同job_name的scrape_config
	 * @param scrapeConfigs scrape_config列表
	 * @param job_name job_name
	 * @return
	 */
	public static boolean isAlreadyExist(List<ScrapeConfig> scrapeConfigs, String job_name) {
		if (job_name == null) return true;
		return scrapeConfigs.stream().anyMatch(sc ->  job_name.equals(sc.getJob_name()));
	}

}
